<?php

/**
 * Description of WrapperApp
 *
 * @author EaDeveloper
 */
class AppSecurity implements EaSoftModule {

    public static $UserData = NULL;
    public $instanceName = "AppSecurity";
    public $db;
    public $includePath;
    public $errores = array();

    public function getCssFiles() {
        ?>
        <link href="<?php echo RELATIVE_PATH; ?>css/security.css" rel="stylesheet" type="text/css" />
        <?php
    }

    public function getJsFiles() {
        
    }

    public function getWindowTitle() {
        return "Seguridad";
    }

    public function isLogged() {
        if (isset($_SESSION[USUARIO])) {
            self::$UserData = unserialize($_SESSION[USUARIO]);
            return true;
        }
        return false;
    }

    public function usuarioValido() {
        $this->db = DbManager::getMe();
        $boSec = BoSecurity::getMe();
        if (!isEmpty(getParam("usuario")) && !isEmpty(getParam("clave"))) {
            $r = $this->db->queryToArray(sprintf("select * from kairos_app_user where USER_NAME='%s' and PASSWORD='%s' ", getParam("usuario"), md5(getParam("clave"))));
            if (count($r) > 0) {
                $r = $r[0];
                self::$UserData = array("usuario" => getParam("usuario"), "data" => $r);
                $_SESSION[USUARIO] = serialize(self::$UserData);
                $boSec->registrarAccion("Ingreso al sistema!", "Ha iniciado session correctamente");
                return true;
            } else {
                $this->errores[] = "Usuario o clave invalidos!";
                $boSec->registrarAccion("Intento fallido de ingresar!", "Ocurrio error cuando intento ingrear al sistema");
            }
        } else {
            $this->errores[] = "Datos de usuario incompletos!";
        }
        return false;
    }

    public function main() {
        include MODULES . DS . "security/main.php";
    }

}
?>
